<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        .father {
            position: relative;
            width: 200px;
            height: 200px;
            background-color: red;
        }

        .son {
            position: absolute;
            top: 10px;
            right: 10px;
            width: 20px;
            height: 20px;
            background-color: pink;
            color: #000;
            font-size: 20px;
            line-height: 20px;
            text-align: center;
        }
    </style>
</head>

<body>
    <div class="father">
        <div class="son">X</div>
    </div>

    <script>
        // 获取儿子对象
        const son = document.querySelector('.son')
        son.addEventListener('click', function () {
            // 利用查找DOM节点的方法根据子节点查找父节点可以少获取一次对象
            son.parentNode.style.display = 'none'
        })

    </script>
</body>

</html>